/**
 * // Definition for a Node.
 * function Node(val, children) {
 *    this.val = val;
 *    this.children = children;
 * };
 */

/**
 * @param {Node|null} root
 * @return {number[]}
 */
 var preorder = function(root) {
    let res = []
    const tools = (root)=>{
        if(!root) return
        res.push(root.val)
        for(let i = 0;i<root.children.length;i++){
            tools(root.children[i])
        }
    }
    tools(root)

    return res
};